package com.framework;

import java.io.FileOutputStream;
import java.io.PrintStream;
import java.lang.reflect.Field;

/**
 * @ClassName MybatisUtil
 * @Description TODO
 * @Author 2214361854
 * @Date 2022/3/4 21:31
 * @Version 1.0
 */
public class MybatisUtil {
    /**
     * 保存任意类型对象
     * @param obj
     */
    public static void save(Object obj){
        try(
                PrintStream ps = new PrintStream(new FileOutputStream("E:\\Text1.txt",true));
            ) {
             //获取类
            Class c = obj.getClass();
            ps.println("==================="+c.getSimpleName()+"====================");
            //获取全部成员变量
            Field[] fields = c.getDeclaredFields();
            //提取成员变量
            for (Field field : fields) {
                String name = field.getName();
                //暴力反射
                field.setAccessible(true);
                String value = field.get(obj) + "";
                ps.println(name+"="+value);
            }
        } catch (Exception e) {
                e.printStackTrace();
        }
    }
}
